package com.FengChaoSystem.service.RegisterService;

import com.FengChaoSystem.dao.RegisterDao;
import com.FengChaoSystem.pojo.Order;
import com.FengChaoSystem.pojo.User;
import com.FengChaoSystem.service.RegisterImpl;
import com.FengChaoSystem.untils.SqlSessionFactoryUtils;
import com.Mybatis.session.SqlSession;
import com.Mybatis.session.SqlSessionFactory;

public class RegisterService implements RegisterImpl {
    SqlSessionFactory sqlSessionFactory= SqlSessionFactoryUtils.getSqlSessionFactory();
    @Override
    public User hasUser(User target) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        RegisterDao mapper = sqlSession.getMapper(RegisterDao.class);
        User result = mapper.hasUser(target);
        sqlSession.close();
        return result;
    }

    @Override
    public void registerUser(User user) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        RegisterDao mapper = sqlSession.getMapper(RegisterDao.class);
        mapper.registerUser(user);
        sqlSession.commit();
        sqlSession.close();

    }

    @Override
    public User selectUserIdByName(User target) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        RegisterDao mapper = sqlSession.getMapper(RegisterDao.class);
        User user = mapper.selectUserIdByName(target);
        sqlSession.close();
        return user;
    }

    @Override
    public void updateAllMyOrderByPhone(Order target) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        RegisterDao mapper = sqlSession.getMapper(RegisterDao.class);
        mapper.updateAllMyOrderByPhone(target);
        sqlSession.commit();
        sqlSession.close();
    }
}
